package com.zr.userLive.controller;


import com.zr.meiju.EnquiryStatus1;
import com.zr.meiju.EnquiryStatus2;
import com.zr.meiju.EnquiryStatus3;
import com.zr.userLive.pojo.UserLiveAddVo;
import com.zr.userLive.pojo.XiaLaVo;
import com.zr.userLive.service.UserLiveService;
import com.zr.util.ResultVOBuilder;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/7/3.
 */
@RestController
public class UserLiveController {

    @Autowired
    private UserLiveService userLiveService;

    /**
     *婚姻状况下拉框接口
     */
    @GetMapping("/hunyinDropdownBox")
    public ResultVo<List<XiaLaVo>> hunyinDropdownBox(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (int i = 0; i< EnquiryStatus1.values().length; i++){
            XiaLaVo xiaLaVo = new XiaLaVo();
            xiaLaVo.setId(i);
            xiaLaVo.setName(EnquiryStatus1.getName(i));
            xiaLaVoList.add(xiaLaVo);
        }
        return ResultVOBuilder.success(xiaLaVoList);
    }

    /**
     *居住状态下拉框接口
     */
    @GetMapping("/juzhuDropdownBox")
    public ResultVo<List<XiaLaVo>> juzhuDropdownBox(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (int i = 0; i< EnquiryStatus2.values().length; i++){
            XiaLaVo xiaLaVo = new XiaLaVo();
            xiaLaVo.setId(i);
            xiaLaVo.setName(EnquiryStatus2.getName(i));
            xiaLaVoList.add(xiaLaVo);
        }
        return ResultVOBuilder.success(xiaLaVoList);
    }


    /**
     *年限下拉框接口
     */
    @GetMapping("/nianxianDropdownBox")
    public ResultVo<List<XiaLaVo>> nianxianDropdownBox(){
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (int i = 0; i< EnquiryStatus3.values().length; i++){
            XiaLaVo xiaLaVo = new XiaLaVo();
            xiaLaVo.setId(i);
            xiaLaVo.setName(EnquiryStatus3.getName(i));
            xiaLaVoList.add(xiaLaVo);
        }
        return ResultVOBuilder.success(xiaLaVoList);
    }

    /**
     *添加
     */
    @PostMapping("/userLive")
    public ResultVo essentialInformation(@RequestBody @Valid UserLiveAddVo userLiveAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVOBuilder.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return userLiveService.userPicture(userLiveAddVo);
    }

    /**
     * 根据loginId查询
     */
    @PostMapping("userPicture")
    public ResultVo queryLoginId(HttpServletRequest request){
        Integer loginId = (Integer) request.getSession().getAttribute("loginId");
        return userLiveService.queryLoginId(loginId);

    }

    /**
     * 上一页查看
     */
    @RequestMapping("/queryByUserIfoid")
    public ResultVo queryByUserIfoid(@RequestParam("id")Integer id){

        return userLiveService.queryByUserIfoid(id);
}
}
